package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController("adminOrderController")
@Api(tags = "订单管理接口")
@RequestMapping("/admin/order")
public class OrderController {

    @Resource
    private OrdersService ordersService;

    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result<PageResult> search(OrdersPageQueryDTO pageQueryDTO){
        PageResult pageResultList = ordersService.search(pageQueryDTO);
        return Result.success(pageResultList);
    }

    @ApiOperation("订单状态统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> OrderStatistics(){
        OrderStatisticsVO orderStatisticsVO = ordersService.orderStatistics();
        return Result.success(orderStatisticsVO);
    }

    @ApiOperation("根据ID查询订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> orderDetails(@PathVariable Long id){
        OrderVO orderVO = ordersService.getOrderDetailsById(id);
        return Result.success(orderVO);
    }

    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result orderConfirm(@RequestBody OrdersConfirmDTO confirmDTO){
        ordersService.orderConfirm(confirmDTO);
        return Result.success();
    }

    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result OrderRejection(@RequestBody OrdersRejectionDTO rejectionDTO){
        ordersService.orderRejection(rejectionDTO);
        return Result.success();
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result OrderCancel(@RequestBody OrdersCancelDTO cancelDTO){
        ordersService.orderCancel(cancelDTO);
        return Result.success();
    }

    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result OrderDelivery(@PathVariable Long id){
        ordersService.orderDelivery(id);
        return Result.success();
    }

    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result OrderComplete(@PathVariable Long id){
        ordersService.orderComplete(id);
        return Result.success();
    }
}
